<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>nextTick</h2>
      <p>{{ count }}</p>
      <button @click="fn">btn</button>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const { createApp } = Vue;

      createApp({
        data() {
          return {
            count: 1,
          };
        },
        methods: {
          async fn() {
            // 结论是直接变成4
            // update阶段，数据的改变和页面的渲染不是一起发生，虚拟dom有关
            // 为了减少页面渲染的次数
            this.count++;
            // setTimeout(() => {
            //   this.count++;
            // }, 0);

            // this.$nextTick让里面的回调函数在下一轮事件轮询中调用
            // this.$nextTick就是等待页面渲染结束
            // this.$nextTick(() => {
            //   this.count++;
            // });

            await this.$nextTick();
            this.count++;
            await this.$nextTick();
            this.count++;
          },

          mounted() {
            // 请求
            // this.list = res.result;
            // this.$nectTick(() => {
            //   console.log(this.$refs.box.height);
            // });
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
